<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
 '
 ' Copyright 2007 Liu, Xiaokang <4341322@gmail.com>
 ' Blog <http://www.ioio.name/>
 ' 
 ' This file is part of JOS(Judge Online System).
 ' You can see this project at <http://code.google.com/p/judgeonline/>
 ' 
 ' JOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 ' published by the Free Software Foundation; either revision 3 of the License, or (at your option) any later revision.
 ' 
 ' JOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 ' 
 ' You should have received a copy of the GNU General Public License along with JOS. if not, see
 ' <http://www.gnu.org/licenses/>.
 '
%>
<%Option Explicit%>
<%
  Dim PageTitle
  PageTitle="Print Task"
%>
<!--#include file="Header.asp"-->
<meta http-equiv="refresh" content="30" />
<div id="Main">
  <div class="Recordsx" id="Records">
  <div id="ProblemsTitle">Print Task List</div>
  <%
        Dim PrevPage,NextPage,MaxPerPage,selectStr,TempPage
		MaxPerPage=25
		
		If Not IsEmpty(Request.QueryString("PrevPage")) and IsNumeric(Request.QueryString("PrevPage")) Then 
	    'Response.Write("PrevPage"+Request.QueryString("PrevPage"))
		TempPage=CInt(Request.QueryString("PrevPage"))
		TempPage=TempPage+MaxPerPage
		'Response.Write(TempPage)
		selectStr="SELECT Top "+CStr(MaxPerPage)+" Length = DATALENGTH(Contents)/2,[C_P_Id],[Uid],[Cid],[SubmitTime],[AcceptedTime],[Accepted] From [Contest_Print] Where Cid=0 and Rid<"+CStr(TempPage)+" and Rid>="+Request.QueryString("PrevPage")+" Order by Rid Desc"
		Else
		If Not IsEmpty(Request.QueryString("NextPage")) and IsNumeric(Request.QueryString("NextPage")) Then
		'Response.Write("NextPage"+Request.QueryString("NextPage"))
		selectStr="SELECT Top "+CStr(MaxPerPage)+"  Length = DATALENGTH(Contents)/2,[C_P_Id],[Uid],[Cid],[SubmitTime],[AcceptedTime],[Accepted] From [Contest_Print] Where Cid=0 and Rid<"+Request.QueryString("NextPage")+" Order by Rid Desc"
		Else
		'Response.Write("Null")
		selectStr="SELECT Top "+CStr(MaxPerPage)+"  Length = DATALENGTH(Contents)/2,[C_P_Id],[Uid],[Cid],[SubmitTime],[PrintedTime],[Printed] From [Contest_Print] Order by [SubmitTime] Desc"
		End If
	    End If	
		
  	    Dim Sr,Rs
		conn.Open connstr
		Set Sr = Server.CreateObject("ADODB.Recordset")
		Sr.Open selectStr,conn,1,3
		Sr.PageSize=MaxPerPage
   %>
   <div>Last <%=MaxPerPage%> submitted</div>
    <table border="0" id="RecordList" style="border-bottom:#879BFF 1px dashed">
      <tr id="RecordListMenu">
        <td width="70">Run ID</td>
        <td width="120">Author</td>
        <td width="40">Con.Id</td>
        <td width="140">Contents</td>
        <td>Submit Time</td>
        <td width="130">Printed Time</td>
        <td>Printed</td>               
      </tr>      
	  	  <% 
		  If Not Sr.eof and Not Sr.Bof then
		  
		  Dim i,MaxRid,MinRid
		  i=0
		  MaxRid=Sr("C_P_Id")
		  Do While Not Sr.eof
		  %>
      <tr id="R<%=Sr("C_P_Id")%>" <% if i mod 2=1 then %>class="RecordList_EvenRow"><%else%>>
	  <%end if
	  i=i+1
	  %>
        <td>CP<%=Sr("C_P_Id")%></td>
        <td><a href="User_Status.asp?Uid=<%=Sr("Uid")%>">
		<%Set Rs = Server.CreateObject("ADODB.Recordset")
		Rs.Open "Select Username From [Members] Where Uid="+Cstr(Sr("Uid")),conn,1,3
	    If Not Rs.eof and Not Rs.Bof Then
		Response.Write(Rs("Username"))
		Else
		Response.Write("Unknown")
		End if
		
	    Rs.Close
		set Rs=nothing%></a></td>
        <td><%=Sr("Cid")%></td>
        <td><a href="Contest_Print_View.asp?Pid=<%=Sr("C_P_Id")%>" title="View"><%=Sr("Length")%>B</a></td>
        <td><%=Sr("SubmitTime")%></td>
        <td><%=Sr("PrintedTime")%></td>        
        <td><%=Sr("Printed")%></td>      
      </tr>
	  <%
	  MinRid=Sr("C_P_Id")
	  If i>=MaxPerPage then exit do 
	  Sr.MoveNext
	  Loop
	  Else%>
      <tr>
        <td colspan="9">No Record</td>
      </tr>
      <%End If%>
    </table>
     <div>&lt;&lt; First Page&nbsp;&nbsp;&nbsp;&nbsp;<a href="?PrevPage=<%=MaxRid%>">&lt;Prev Page</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="?NextPage=<%=MinRid%>">Next Page&gt;</a>&nbsp;&nbsp;&nbsp;&nbsp;Last Page &gt;&gt;</div>
	<%
		Sr.Close
		Set Sr=nothing		
		conn.Close
   %>
  
  </div>
</div>
<!--#include file="Footer.asp"-->